package com.timothy.android;

import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

public class MessageSender {
	public static String PC_IP;
	public static int PC_PORT = 9999;

	public static boolean sendMessage(String command){
		System.out.println( command );
		try {
			Socket socket = new Socket(PC_IP, Integer.valueOf(PC_PORT));
			PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
			out.print(command  );
			out.close();
			socket.close();
			return true;
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
	
	}
	
	
	public static void main(String[] args){
		MessageSender.PC_IP="192.168.240.177";
		MessageSender.PC_PORT=9999;
		String message = "<Message Type=\"CommonQuestion\">" +
						 "<Content>" +
						 "<Question Type=\"stTwoButtonAlpha\" SlideIndex=\"1\" QuestionName=\"a test\">" +
						 	"<Choice Index=\"1\" Text=\"True\"/>"+
						 	"<Choice Index=\"2\" Text=\"xxxx\"/>"+
						 	"</Question>" +       
						  "</Content>" +
						  "</Message>";
//		String message2 = "<Message Type=\"CommonQuestion\">" +
//		 "<Content>" +
//		 "<Question Type=\"stTwoButtonAlpha\" SlideIndex=\"1\" QuestionName=\"a test\">" +
//		 	"<Choice Index=\"1\" Text=\"True\"/>"+
//		 	"<Choice Index=\"2\" Text=\"xxxx\"/>"+
//		 	"</Question>" +       
//		  "</Content>" +
//		  "</Message>";
		
		System.out.println(message);
		sendMessage(message);
	}
}
